package com.sise.wangzhan;

import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname ChoseServerTest
 * @Description TODO
 * @Date 2020/3/25 20:28
 * @Created by wangzhan
 */
public class ChoseServerTest {
    public static void main(String[] args) {
        //创建负载均衡器
        //ILoadBalancer Ib = new BaseLoadBalancer();//使用默认的负载规则

        //设置自定义的负载规则
        BaseLoadBalancer Ib = new BaseLoadBalancer();
        Ib.setRule(new MyRule(Ib));


        //添加服务器
        List<Server> servers = new ArrayList<Server>();
        servers.add(new Server("localhost", 8081));
        servers.add(new Server("localhost", 8085));
        Ib.addServers(servers);

        //服务器选择
        for (int i = 0; i < 6; i++) {
            Server s = Ib.chooseServer(null);
            System.out.println(s);
        }




    }
}
